﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAL;

/// <summary>
/// Summary description for AccountBO
/// </summary>
public class AccountBO : DTPReportDataContext
{
    public AccountBO()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public bool AccountCheckEmail(string strEmail)
    {
        try
        {
            int result = PRC_DTP_ACCOUNT_CHECKEMAIL(strEmail);
            if (result == 1)
                return true;
            else
                return false;
        }
        catch
        {
            return false;
        }
    }

    public bool AccountChangePass(int UserID, string oldPass, string newPass)
    {
        try
        {
            int result = PRC_DTP_ACCOUNT_CHANGEPASS(UserID, oldPass, newPass);
            if (result == 1)
                return true;
            else
                return false;
        }
        catch
        {
            return false;
        }
    }

    public int AccountInsert(DTP_ACCOUNT objAccount)
    {
        try
        {
            DTP_ACCOUNT Acc = new DTP_ACCOUNT();
            Acc = objAccount;
            return PRC_DTP_ACCOUNT_INSERT(Acc.USERNAME, Acc.PASSWORD, Acc.FIRSTNAME, Acc.LASTNAME, Acc.PHONE, Acc.EMAIL, Acc.MSBOPHAN, objAccount.CSID, Acc.ACTIVE);

        }
        catch
        {
            return -1;
        }
    }

    public bool AccountUpdate(DTP_ACCOUNT objAccount)
    {
        try
        {
            DTP_ACCOUNT Acc = new DTP_ACCOUNT();
            Acc = objAccount;
            int result = PRC_DTP_ACCOUNT_UPDATE(Acc.USERID, Acc.USERNAME, Acc.PASSWORD, Acc.FIRSTNAME, Acc.LASTNAME, Acc.PHONE, Acc.EMAIL, Acc.MSBOPHAN, objAccount.CSID, Acc.ACTIVE);
            if (result == 1)
                return true;
            else
                return false;
        }
        catch
        {
            return false;
        }
    }
    public bool AccountUpdatePasswordByEmail(string email, string pass)
    {
        try
        {
            int result = PRC_DTP_ACCOUNT_UPDATEBYEMAIL(email, pass);
            if (result == 1)
                return true;
            else
                return false;
        }
        catch
        {
            return false;
        }
    }
    public PRC_DTP_ACCOUNT_GETLISTBYUSERIDResult AccountGetListByUserID(int UserID)
    {
        try
        {
            PRC_DTP_ACCOUNT_GETLISTBYUSERIDResult result = new PRC_DTP_ACCOUNT_GETLISTBYUSERIDResult();
            result = PRC_DTP_ACCOUNT_GETLISTBYUSERID(UserID).SingleOrDefault();
            return result;
        }
        catch (Exception ex)
        {
            return null;
        }
    }
    public PRC_DTP_ACCOUNT_GETLISTResult AccountGetList(DTP_ACCOUNT objAccount)
    {
        try
        {
            PRC_DTP_ACCOUNT_GETLISTResult result = new PRC_DTP_ACCOUNT_GETLISTResult();
            result = PRC_DTP_ACCOUNT_GETLIST(objAccount.USERNAME, objAccount.PASSWORD).SingleOrDefault();
            return result;
        }
        catch (Exception ex)
        {
            return null;
        }
    }
    public List<PRC_DTP_ACCOUNT_GETALLResult> AccountGetAll()
    {
        try
        {
            List<PRC_DTP_ACCOUNT_GETALLResult> result = new List<PRC_DTP_ACCOUNT_GETALLResult>();
            result = PRC_DTP_ACCOUNT_GETALL().ToList();
            return result;
        }
        catch (Exception ex)
        {
            return null;
        }
    }
    public List<PRC_DTP_ACCOUNT_SEARCHResult> AccountGet_Search(DTP_ACCOUNT objAccount)
    {
        try
        {
            List<PRC_DTP_ACCOUNT_SEARCHResult> result = new List<PRC_DTP_ACCOUNT_SEARCHResult>();
            result = PRC_DTP_ACCOUNT_SEARCH(objAccount.USERNAME, objAccount.FIRSTNAME, objAccount.LASTNAME, objAccount.PHONE, objAccount.EMAIL, objAccount.MSBOPHAN, objAccount.CSID, objAccount.ACTIVE).ToList();
            return result;
        }
        catch (Exception ex)
        {
            return null;
        }
    }

    public List<PRC_DTP_CS_GETLISTBYIDResult> CSGetListByID(int Id)
    {
        try
        {
            return PRC_DTP_CS_GETLISTBYID(Id).ToList();
        }
        catch (Exception ex)
        {
            return null;
        }
    }
}